﻿namespace HuaWei.CBR.QTJL
{
    using DevExpress.Data;
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Controls;
    using DevExpress.XtraEditors.Repository;
    using DevExpress.XtraGrid;
    using DevExpress.XtraGrid.Columns;
    using DevExpress.XtraGrid.Views.Base;
    using DevExpress.XtraGrid.Views.Grid;
    using HuaWei.CommClass;
    using HuaWei.CommComp;
    using HuaWei.Windows.Forms;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FrmJGTZ_HGMS : FrmBase
    {
        private BindingSource bindingSource;
        private BindingSource bindingSource1;
        private GridColumn gridColumn1;
        private GridColumn gridColumn2;
        private GridColumn gridColumn3;
        private GridColumn gridColumn30;
        private GridColumn gridColumn31;
        private GridColumn gridColumn4;
        private GridColumn gridColumn5;
        private GridColumn gridColumn6;
        private GridColumn gridColumn7;
        private GridControl gridControl3;
        private GridControl gridControl7;
        private GridView gridView1;
        private GridView gridView7;
        private IContainer icontainer1 = null;
        private MemoEdit memoEdit1;
        private PanelControl panelControl1;
        private PanelControl panelControl2;
        private PanelControl panelControl3;
        private RepositoryItemCheckEdit repositoryItemCheckEdit1;
        private SimpleButton simpleButton1;
        private SimpleButton simpleButton13;
        private SimpleButton simpleButton18;
        private SimpleButton simpleButton19;
        private SimpleButton simpleButton2;
        private SimpleButton simpleButton3;
        private TextEdit textEdit1;

        public FrmJGTZ_HGMS()
        {
            this.InitializeComponent();
        }

        private void bindingSource_PositionChanged(object sender, EventArgs e)
        {
            this.ControlFormStatus();
            this.method3();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.icontainer1 != null))
            {
                this.icontainer1.Dispose();
            }
            base.Dispose(disposing);
        }

        private void FrmJGTZ_HGMS_Load(object sender, EventArgs e)
        {
            this.LoadData();
        }

        private void gridView7_CellValueChanged(object sender, CellValueChangedEventArgs e)
        {
            if (e.Column.FieldName.Equals("TYSB"))
            {
                if (CHelp.ConvertInt(e.Value, 0).Equals(1))
                {
                    DevCCHelp.ControlForm(base.Controls, true, 1);
                }
                else
                {
                    DevCCHelp.ControlForm(base.Controls, false, 1);
                }
            }
        }

        private void InitializeComponent()
        {
            this.icontainer1 = new Container();
            this.gridControl3 = new GridControl();
            this.bindingSource1 = new BindingSource(this.icontainer1);
            this.gridView1 = new GridView();
            this.gridColumn1 = new GridColumn();
            this.gridColumn2 = new GridColumn();
            this.gridColumn3 = new GridColumn();
            this.gridColumn4 = new GridColumn();
            this.gridColumn5 = new GridColumn();
            this.gridColumn6 = new GridColumn();
            this.panelControl3 = new PanelControl();
            this.simpleButton13 = new SimpleButton();
            this.simpleButton18 = new SimpleButton();
            this.gridControl7 = new GridControl();
            this.bindingSource = new BindingSource(this.icontainer1);
            this.gridView7 = new GridView();
            this.gridColumn7 = new GridColumn();
            this.gridColumn30 = new GridColumn();
            this.gridColumn31 = new GridColumn();
            this.repositoryItemCheckEdit1 = new RepositoryItemCheckEdit();
            this.panelControl2 = new PanelControl();
            this.simpleButton3 = new SimpleButton();
            this.simpleButton2 = new SimpleButton();
            this.simpleButton19 = new SimpleButton();
            this.simpleButton1 = new SimpleButton();
            this.panelControl1 = new PanelControl();
            this.memoEdit1 = new MemoEdit();
            this.textEdit1 = new TextEdit();
            base.ds.BeginInit();
            base.dsQuery.BeginInit();
            base.dataSets.BeginInit();
            this.gridControl3.BeginInit();
            ((ISupportInitialize) this.bindingSource1).BeginInit();
            this.gridView1.BeginInit();
            this.panelControl3.BeginInit();
            this.panelControl3.SuspendLayout();
            this.gridControl7.BeginInit();
            ((ISupportInitialize) this.bindingSource).BeginInit();
            this.gridView7.BeginInit();
            this.repositoryItemCheckEdit1.BeginInit();
            this.panelControl2.BeginInit();
            this.panelControl2.SuspendLayout();
            this.panelControl1.BeginInit();
            this.panelControl1.SuspendLayout();
            this.memoEdit1.Properties.BeginInit();
            this.textEdit1.Properties.BeginInit();
            base.SuspendLayout();
            this.gridControl3.DataSource = this.bindingSource1;
            this.gridControl3.Dock = DockStyle.Fill;
            this.gridControl3.EmbeddedNavigator.Buttons.Edit.Visible = false;
            this.gridControl3.Location = new Point(0xfc, 0x9b);
            this.gridControl3.MainView = this.gridView1;
            this.gridControl3.Name = "gridControl3";
            this.gridControl3.Size = new Size(0x26e, 0x14c);
            this.gridControl3.TabIndex = 0x13;
            this.gridControl3.ViewCollection.AddRange(new DevExpress.XtraGrid.Views.Base.BaseView[] { this.gridView1 });
            this.gridView1.Columns.AddRange(new GridColumn[] { this.gridColumn1, this.gridColumn2, this.gridColumn3, this.gridColumn4, this.gridColumn5, this.gridColumn6 });
            this.gridView1.GridControl = this.gridControl3;
            this.gridView1.Name = "gridView1";
            this.gridView1.OptionsCustomization.AllowFilter = false;
            this.gridView1.OptionsCustomization.AllowSort = false;
            this.gridView1.OptionsView.ColumnAutoWidth = false;
            this.gridView1.OptionsView.ShowFooter = true;
            this.gridView1.OptionsView.ShowGroupPanel = false;
            this.gridColumn1.Caption = "项目名称";
            this.gridColumn1.FieldName = "XMMC";
            this.gridColumn1.Name = "gridColumn1";
            this.gridColumn1.Visible = true;
            this.gridColumn1.VisibleIndex = 0;
            this.gridColumn2.Caption = "单位";
            this.gridColumn2.FieldName = "DW";
            this.gridColumn2.Name = "gridColumn2";
            this.gridColumn2.Visible = true;
            this.gridColumn2.VisibleIndex = 1;
            this.gridColumn3.Caption = "计算期内用量[YL]";
            this.gridColumn3.FieldName = "YL";
            this.gridColumn3.Name = "gridColumn3";
            this.gridColumn3.Visible = true;
            this.gridColumn3.VisibleIndex = 3;
            this.gridColumn3.Width = 0x6d;
            this.gridColumn4.Caption = "材料当前价格[JG1]";
            this.gridColumn4.FieldName = "JG1";
            this.gridColumn4.Name = "gridColumn4";
            this.gridColumn4.SummaryItem.SummaryType = SummaryItemType.Sum;
            this.gridColumn4.Visible = true;
            this.gridColumn4.VisibleIndex = 2;
            this.gridColumn4.Width = 0x72;
            this.gridColumn5.Caption = "材料基期价格[JG0]";
            this.gridColumn5.FieldName = "JG0";
            this.gridColumn5.Name = "gridColumn5";
            this.gridColumn5.SummaryItem.SummaryType = SummaryItemType.Sum;
            this.gridColumn5.Visible = true;
            this.gridColumn5.VisibleIndex = 4;
            this.gridColumn5.Width = 0x72;
            this.gridColumn6.Caption = "调价额[YJE]";
            this.gridColumn6.FieldName = "YJE";
            this.gridColumn6.Name = "gridColumn6";
            this.gridColumn6.SummaryItem.SummaryType = SummaryItemType.Sum;
            this.gridColumn6.Visible = true;
            this.gridColumn6.VisibleIndex = 5;
            this.gridColumn6.Width = 0x6a;
            this.panelControl3.Controls.Add(this.simpleButton13);
            this.panelControl3.Controls.Add(this.simpleButton18);
            this.panelControl3.Dock = DockStyle.Top;
            this.panelControl3.Location = new Point(0xfc, 0x7f);
            this.panelControl3.Name = "panelControl3";
            this.panelControl3.Size = new Size(0x26e, 0x1c);
            this.panelControl3.TabIndex = 0x16;
            this.simpleButton13.Dock = DockStyle.Left;
            this.simpleButton13.Location = new Point(0x34, 2);
            this.simpleButton13.Name = "simpleButton13";
            this.simpleButton13.Size = new Size(50, 0x18);
            this.simpleButton13.TabIndex = 6;
            this.simpleButton13.Text = "删除";
            this.simpleButton13.Click += new EventHandler(this.simpleButton13_Click);
            this.simpleButton18.Dock = DockStyle.Left;
            this.simpleButton18.Location = new Point(2, 2);
            this.simpleButton18.Name = "simpleButton18";
            this.simpleButton18.Size = new Size(50, 0x18);
            this.simpleButton18.TabIndex = 5;
            this.simpleButton18.Text = "新增";
            this.simpleButton18.Click += new EventHandler(this.simpleButton18_Click);
            this.gridControl7.DataSource = this.bindingSource;
            this.gridControl7.Dock = DockStyle.Left;
            this.gridControl7.EmbeddedNavigator.Buttons.Edit.Visible = false;
            this.gridControl7.Location = new Point(0, 0x7f);
            this.gridControl7.MainView = this.gridView7;
            this.gridControl7.Name = "gridControl7";
            this.gridControl7.RepositoryItems.AddRange(new RepositoryItem[] { this.repositoryItemCheckEdit1 });
            this.gridControl7.Size = new Size(0xfc, 360);
            this.gridControl7.TabIndex = 0x15;
            this.gridControl7.ViewCollection.AddRange(new DevExpress.XtraGrid.Views.Base.BaseView[] { this.gridView7 });
            this.bindingSource.DataSource = base.dataSets;
            this.bindingSource.Position = 0;
            this.bindingSource.PositionChanged += new EventHandler(this.bindingSource_PositionChanged);
            this.gridView7.Columns.AddRange(new GridColumn[] { this.gridColumn7, this.gridColumn30, this.gridColumn31 });
            this.gridView7.GridControl = this.gridControl7;
            this.gridView7.Name = "gridView7";
            this.gridView7.OptionsCustomization.AllowFilter = false;
            this.gridView7.OptionsCustomization.AllowSort = false;
            this.gridView7.OptionsDetail.AllowZoomDetail = false;
            this.gridView7.OptionsDetail.EnableMasterViewMode = false;
            this.gridView7.OptionsDetail.ShowDetailTabs = false;
            this.gridView7.OptionsView.ColumnAutoWidth = false;
            this.gridView7.OptionsView.ShowDetailButtons = false;
            this.gridView7.OptionsView.ShowFooter = true;
            this.gridView7.OptionsView.ShowGroupPanel = false;
            this.gridView7.CellValueChanged += new CellValueChangedEventHandler(this.gridView7_CellValueChanged);
            this.gridColumn7.Caption = "批次";
            this.gridColumn7.FieldName = "PCH";
            this.gridColumn7.Name = "gridColumn7";
            this.gridColumn7.Visible = true;
            this.gridColumn7.VisibleIndex = 0;
            this.gridColumn30.Caption = "批次金额";
            this.gridColumn30.FieldName = "PCJE";
            this.gridColumn30.Name = "gridColumn30";
            this.gridColumn30.OptionsColumn.AllowEdit = false;
            this.gridColumn30.SummaryItem.SummaryType = SummaryItemType.Sum;
            this.gridColumn30.Visible = true;
            this.gridColumn30.VisibleIndex = 1;
            this.gridColumn30.Width = 80;
            this.gridColumn31.Caption = "同意上报";
            this.gridColumn31.ColumnEdit = this.repositoryItemCheckEdit1;
            this.gridColumn31.FieldName = "TYSB";
            this.gridColumn31.Name = "gridColumn31";
            this.gridColumn31.Tag = "-1";
            this.gridColumn31.Visible = true;
            this.gridColumn31.VisibleIndex = 2;
            this.gridColumn31.Width = 60;
            this.repositoryItemCheckEdit1.AutoHeight = false;
            this.repositoryItemCheckEdit1.DisplayValueChecked = "1";
            this.repositoryItemCheckEdit1.DisplayValueUnchecked = "0";
            this.repositoryItemCheckEdit1.Name = "repositoryItemCheckEdit1";
            this.repositoryItemCheckEdit1.NullStyle = StyleIndeterminate.Unchecked;
            this.repositoryItemCheckEdit1.ValueChecked = 1;
            this.repositoryItemCheckEdit1.ValueUnchecked = 0;
            this.panelControl2.Controls.Add(this.simpleButton3);
            this.panelControl2.Controls.Add(this.simpleButton2);
            this.panelControl2.Controls.Add(this.simpleButton19);
            this.panelControl2.Controls.Add(this.simpleButton1);
            this.panelControl2.Dock = DockStyle.Top;
            this.panelControl2.Location = new Point(0, 0x63);
            this.panelControl2.Name = "panelControl2";
            this.panelControl2.Size = new Size(0x36a, 0x1c);
            this.panelControl2.TabIndex = 20;
            this.simpleButton3.Dock = DockStyle.Left;
            this.simpleButton3.Location = new Point(0xaf, 2);
            this.simpleButton3.Name = "simpleButton3";
            this.simpleButton3.Size = new Size(0x3a, 0x18);
            this.simpleButton3.TabIndex = 0x18;
            this.simpleButton3.Tag = "-2";
            this.simpleButton3.Text = "关闭";
            this.simpleButton3.Click += new EventHandler(this.simpleButton3_Click);
            this.simpleButton2.Dock = DockStyle.Left;
            this.simpleButton2.Location = new Point(0x75, 2);
            this.simpleButton2.Name = "simpleButton2";
            this.simpleButton2.Size = new Size(0x3a, 0x18);
            this.simpleButton2.TabIndex = 0x17;
            this.simpleButton2.Tag = "-2";
            this.simpleButton2.Text = "过程数据";
            this.simpleButton2.Click += new EventHandler(this.simpleButton2_Click);
            this.simpleButton19.Dock = DockStyle.Left;
            this.simpleButton19.Location = new Point(60, 2);
            this.simpleButton19.Name = "simpleButton19";
            this.simpleButton19.Size = new Size(0x39, 0x18);
            this.simpleButton19.TabIndex = 0x15;
            this.simpleButton19.Tag = "-1";
            this.simpleButton19.Text = "删除批次";
            this.simpleButton19.Click += new EventHandler(this.simpleButton19_Click);
            this.simpleButton1.Dock = DockStyle.Left;
            this.simpleButton1.Location = new Point(2, 2);
            this.simpleButton1.Name = "simpleButton1";
            this.simpleButton1.Size = new Size(0x3a, 0x18);
            this.simpleButton1.TabIndex = 0x13;
            this.simpleButton1.Tag = "-1";
            this.simpleButton1.Text = "增加批次";
            this.simpleButton1.Click += new EventHandler(this.simpleButton1_Click);
            this.panelControl1.Controls.Add(this.memoEdit1);
            this.panelControl1.Controls.Add(this.textEdit1);
            this.panelControl1.Dock = DockStyle.Top;
            this.panelControl1.Location = new Point(0, 0);
            this.panelControl1.Name = "panelControl1";
            this.panelControl1.Size = new Size(0x36a, 0x63);
            this.panelControl1.TabIndex = 0x12;
            this.memoEdit1.EditValue = "说明：YJE-钢材、燃油料或水泥的调价额；YL-钢材、燃油料或水泥计算期内用量；JG0-钢材、燃油料或水泥基期价格；JG1-钢材、燃油料或水泥当期价格";
            this.memoEdit1.Location = new Point(15, 0x2b);
            this.memoEdit1.Name = "memoEdit1";
            this.memoEdit1.Properties.Appearance.BackColor = Color.WhiteSmoke;
            this.memoEdit1.Properties.Appearance.Options.UseBackColor = true;
            this.memoEdit1.Properties.ReadOnly = true;
            this.memoEdit1.Properties.ScrollBars = ScrollBars.None;
            this.memoEdit1.Size = new Size(0x286, 0x2e);
            this.memoEdit1.TabIndex = 2;
            this.textEdit1.EditValue = "调价公式：YJE=YL(JG1-JG0)\x00d7(1+3.41%)";
            this.textEdit1.Location = new Point(15, 0x10);
            this.textEdit1.Name = "textEdit1";
            this.textEdit1.Properties.Appearance.BackColor = Color.WhiteSmoke;
            this.textEdit1.Properties.Appearance.Options.UseBackColor = true;
            this.textEdit1.Properties.ReadOnly = true;
            this.textEdit1.Size = new Size(260, 0x15);
            this.textEdit1.TabIndex = 0;
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            base.ClientSize = new Size(0x36a, 0x1e7);
            base.Controls.Add(this.gridControl3);
            base.Controls.Add(this.panelControl3);
            base.Controls.Add(this.gridControl7);
            base.Controls.Add(this.panelControl2);
            base.Controls.Add(this.panelControl1);
            base.Name = "FrmJGTZ_HGMS";
            this.Text = "价格调整_黄冈模式调整";
            base.Load += new EventHandler(this.FrmJGTZ_HGMS_Load);
            base.ds.EndInit();
            base.dsQuery.EndInit();
            base.dataSets.EndInit();
            this.gridControl3.EndInit();
            ((ISupportInitialize) this.bindingSource1).EndInit();
            this.gridView1.EndInit();
            this.panelControl3.EndInit();
            this.panelControl3.ResumeLayout(false);
            this.gridControl7.EndInit();
            ((ISupportInitialize) this.bindingSource).EndInit();
            this.gridView7.EndInit();
            this.repositoryItemCheckEdit1.EndInit();
            this.panelControl2.EndInit();
            this.panelControl2.ResumeLayout(false);
            this.panelControl1.EndInit();
            this.panelControl1.ResumeLayout(false);
            this.memoEdit1.Properties.EndInit();
            this.textEdit1.Properties.EndInit();
            base.ResumeLayout(false);
        }

        public override void LoadedForm()
        {
            base.ds.Tables["QTJL_JGTZMX"].ColumnChanging += new DataColumnChangeEventHandler(this.method2);
            base.SetBindingSource(this.bindingSource, "QTJL_JGTZ", true);
            base.SetBindingSource(this.bindingSource1, "QTJL_JGTZMX", false);
            this.bindingSource.Position = this.bindingSource.Count;
            base.LoadedForm();
        }

        public override void LoadingData()
        {
            base.LoadingData();
            base.ds.Clear();
            string str = null;
            str = "select * from QTJL_JGTZ " + Class28.YfQclfhSo(GParams.QCInfo.QCID, "");
            Class39.smethod4(base.ida, base.ds, str, "QTJL_JGTZ", true);
            str = "select * from QTJL_JGTZMX " + Class28.YfQclfhSo(GParams.QCInfo.QCID, "");
            Class39.smethod4(base.ida, base.ds, str, "QTJL_JGTZMX", true);
        }

        private void method1(DataRow dataRow)
        {
            DataRow row = (this.bindingSource.Current as DataRowView).Row;
            if ((this.bindingSource1.Current != null) && (this.bindingSource1.Current is DataRowView))
            {
                decimal num = CHelp.ConvertDecimal(base.ds.Tables["QTJL_JGTZMX"].Compute("sum(YJE)", "PID='" + dataRow["PID"].ToString() + "'"), 0, 0);
                row["PCJE"] = num;
                row.EndEdit();
            }
            else
            {
                row["PCJE"] = 0;
                row.EndEdit();
            }
        }

        private void method2(object sender, DataColumnChangeEventArgs e)
        {
            HGMSTZ hgmstz = new HGMSTZ();
            DataRow row = e.Row;
            if (e.Column.ColumnName.Equals("JG1"))
            {
                hgmstz.JG1 = Convert.ToDecimal(e.ProposedValue);
                hgmstz.JG0 = DHelp.GetValue(row, "JG0");
                hgmstz.YL = DHelp.GetValue(row, "YL");
                row["YJE"] = hgmstz.YJE();
                this.method1(e.Row);
            }
            if (e.Column.ColumnName.Equals("JG0"))
            {
                hgmstz.JG0 = Convert.ToDecimal(e.ProposedValue);
                hgmstz.JG1 = DHelp.GetValue(row, "JG1");
                hgmstz.YL = DHelp.GetValue(row, "YL");
                row["YJE"] = hgmstz.YJE();
                this.method1(e.Row);
            }
            if (e.Column.ColumnName.Equals("YL"))
            {
                hgmstz.YL = Convert.ToDecimal(e.ProposedValue);
                hgmstz.JG0 = DHelp.GetValue(row, "JG0");
                hgmstz.JG1 = DHelp.GetValue(row, "JG1");
                row["YJE"] = hgmstz.YJE();
                this.method1(e.Row);
            }
        }

        private void method3()
        {
            if ((this.bindingSource.Current != null) && (this.bindingSource.Current is DataRowView))
            {
                DataRow row = (this.bindingSource.Current as DataRowView).Row;
                this.bindingSource1.Filter = "PID='" + row["ID"].ToString() + "'";
            }
        }

        private void method4(object sender, EventArgs e)
        {
            base.Save();
        }

        public override void Saving()
        {
            base.Saving();
            this.bindingSource.MoveFirst();
            this.bindingSource.EndEdit();
            this.bindingSource1.MoveFirst();
            this.bindingSource1.EndEdit();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            DHelp.DataAddNew(this.bindingSource, "", "");
            this.method3();
        }

        private void simpleButton13_Click(object sender, EventArgs e)
        {
            if ((this.bindingSource1.List.Count > 0) && (MsgBox.ShowQuestion("是否删除当前记录？") == System.Windows.Forms.DialogResult.OK))
            {
                this.bindingSource1.RemoveCurrent();
                base.Save();
            }
        }

        private void simpleButton18_Click(object sender, EventArgs e)
        {
            if (this.bindingSource.List.Count > 0)
            {
                this.bindingSource.EndEdit();
                DHelp.DataAddMxRow(this.bindingSource1, this.bindingSource);
            }
        }

        private void simpleButton19_Click(object sender, EventArgs e)
        {
            if (this.bindingSource.List.Count > 0)
            {
                if (this.bindingSource1.List.Count > 0)
                {
                    MsgBox.ShowMsg("请删除所有明细信息后继续此操作！");
                }
                else if (MsgBox.ShowQuestion("是否删除当前记录？") == System.Windows.Forms.DialogResult.OK)
                {
                    this.bindingSource.RemoveCurrent();
                    this.bindingSource.EndEdit();
                    base.Save();
                }
            }
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            string objId = DHelp.GetObjId(this.bindingSource);
            base.OpenDataLog("QTJL_JGTZ", GParams._BDID, GParams.QCInfo.QCID, objId);
        }

        private void simpleButton3_Click(object sender, EventArgs e)
        {
            base.Close();
        }
    }
}

